package com.Maykk.Demo01;

import java.util.HashSet;

/**
 * @ClassName: Demo06
 * @Description: TODO HashSet 集合对象去重
 * @Author: MaykkStar@163.com
 */
public class Demo04 {
    public static void main(String[] args) {
        HashSet<Student> stuHS = new HashSet<>();
        stuHS.add(new Student("Lucy", 19));
        stuHS.add(new Student("Andy", 18));
        stuHS.add(new Student("Maya", 16));
        stuHS.add(new Student("LiHua", 15));
        stuHS.add(new Student("Lucy", 19));

        // 在 Student 中重写 HashCode 和 equals 方法，用于 HashCode 集合中对象去重
        for (Student stu : stuHS) {
            System.out.println(stu);
        }

    }
}
